package me.ingxin.android.router.route

import android.content.Context

/**
 * Created by ingxin on 2022/4/18
 */
abstract class RouteHandler {

    /**hold key*/
    @JvmField
    internal var requestKey: String? = null

    @JvmField
    internal var result: Result? = null

    /**
     * 回传执行结果
     */
    protected fun setResult(result: Result) {
        //存在requestKey说明启用了hold
        if (requestKey?.isNotEmpty() == true) {
            RouteHolder.instance.releaseHandler(this, result)
        } else {
            this.result = result
        }
    }

    /**
     * 可以在该方法中做一些资源释放
     */
    open fun onRelease() {

    }

    /**
     * 通过路由方式调用代码
     * @param context 启动时的上下文
     * @param request 路由请求体
     */
    abstract fun handle(context: Context, request: Request)

}